import React, { Component } from "react";
import Tpl from "./tpl";
import "./index.css";
export default class Index extends Component {
  render() {
    return (
      <div>
        <button
          onClick={() => {
            let iframe = document.createElement("iframe");
            document.body.appendChild(iframe);
            let doc = iframe.contentWindow.document;
            // 获取打印模版
            let wrap = document.getElementById("print-tpl").innerHTML;
            doc.write("<div>" + wrap + "</div>");
            doc.close();
            iframe.contentWindow.focus();
            iframe.contentWindow.print();
            // 清除iframe
            let cl = setTimeout(() => {
              clearTimeout(cl);
              document.body.removeChild(iframe);
            }, 100);
          }}
        >
          打印快递单子
        </button>
        {/* 快递单模版 */}
        <Tpl a={10000} />
      </div>
    );
  }
}
